x86/mm: re-arrange type check around _get_page_type()'s TLB flush
authorJan Beulich <jbeulich@suse.com>
Mon, 15 Aug 2022 06:53:11 +0000 (08:53 +0200)
committerJan Beulich <jbeulich@suse.com>
Mon, 15 Aug 2022 06:53:11 +0000 (08:53 +0200)
Checks dependent on only d and x can be pulled out, thus allowing to
skip the flush mask calculation.

(Also-)Suggested-by: Andrew Cooper <andrew.cooper3@citrix.com>
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
xen/arch/x86/mm.c

index 40e132b9ba4468dcabc2317664c8f64307e7209c..db1817b691f85f941e0ab5a180afe8281fc3e8be 100644 (file)
@@ -3020,7 +3020,10 @@ static int _get_page_type(struct page_info *page, unsigned long type,
         if ( d && shadow_mode_enabled(d) )
             shadow_prepare_page_type_change(d, page);
 
-        if ( (x & PGT_type_mask) != type )
+        if ( (x & PGT_type_mask) != type &&
+             /* Shadow mode: track only writable pages. */
+             (!shadow_mode_enabled(d) ||
+              ((x & PGT_type_mask) == PGT_writable_page)) )
         {
             /*
              * On type change we check to flush stale TLB entries. It is
@@ -3035,10 +3038,7 @@ static int _get_page_type(struct page_info *page, unsigned long type,
             /* Don't flush if the timestamp is old enough */
             tlbflush_filter(mask, page->tlbflush_timestamp);
 
-            if ( unlikely(!cpumask_empty(mask)) &&
-                 /* Shadow mode: track only writable pages. */
-                 (!shadow_mode_enabled(d) ||
-                  ((x & PGT_type_mask) == PGT_writable_page)) )
+            if ( unlikely(!cpumask_empty(mask)) )
             {
                 perfc_incr(need_flush_tlb_flush);
                 /*